package com.housekeeping.housekeeping.usermanagement.controller;

import com.alibaba.fastjson.JSONObject;
import com.housekeeping.housekeeping.usermanagement.entity.InformationUser;
import com.housekeeping.housekeeping.usermanagement.entity.MergesUser;
import com.housekeeping.housekeeping.usermanagement.service.OperationService;
import com.housekeeping.housekeeping.usermanagement.service.impl.SelServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/user/sel")
public class SelController extends HttpServlet {
    static OperationService operation = new SelServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        String str = req.getParameter("str");
        String str1 = "0";
        String forward = "0";
        String next = "0";

            List<InformationUser> informationUsers = null;
            try {
                informationUsers = operation.useOperation(str, str1, forward, next);
                //获取集合长度
                int size = informationUsers.size();
                MergesUser mergesUser = new MergesUser(size, informationUsers);
                //转换成json
                resp.getWriter().print(JSONObject.toJSONString(mergesUser));


            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }

    }
}